//
//  HKProfileCell.m
//  HKTimeKitApp
//
//  Created by huzhaoke1 on 2023/5/11.
//

#import "HKProfileCell.h"


static const CGFloat kKSLeftMargin = 24.f;
static const CGFloat kKSMiddleMargin = 9.f;


@interface HKProfileCell ()

@property (nonatomic, strong) UIImageView *titleImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *arrowImageView;

@end

@implementation HKProfileCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleImgView];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.arrowImageView];
        
        [self.titleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kKSLeftMargin);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.titleImgView.mas_right).offset(kKSMiddleMargin);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).offset(-kKSLeftMargin);
            make.centerY.mas_equalTo(self.contentView);
        }];
    }
    return self;
}

+ (CGFloat)cellHeightWithContent:(id)content {
    return 52;
}

- (void)updateContent:(id)content {
    HKProfileCellViewModel *viewModel = KSSAFE_CAST(content, HKProfileCellViewModel);
    [self.titleImgView setImage:[UIImage imageNamed:viewModel.imageName]];
    self.titleLab.text = viewModel.title;
    self.arrowImageView.image = [UIImage imageNamed:viewModel.arrowImageName];
}

#pragma mark - getter & setter
- (UIImageView *)titleImgView {
    if (!_titleImgView) {
        _titleImgView = [UIImageView new];
    }
    return _titleImgView;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel labelWithFont:[HKFontHelper appcnFontWithSize:16.f]
                                  bgColor:nil
                                textColor:UIColorFromRGB(0x333333) textAligment:NSTextAlignmentRight];
    }
    return _titleLab;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [UIImageView new];
    }
    return _arrowImageView;
}

@end

@implementation HKProfileCellViewModel

@end
